/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pbl;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.List;

public class PersonHandler implements Runnable {

    Socket socket;
    List personList;

    public PersonHandler(Socket socket, List personList) {
        System.out.println("Setting up a PersonHandler");
        this.socket = socket;
        this.personList = personList;
    }

    public void run() {
        System.out.println("Inside run...");
        try {
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();

            ObjectOutputStream oos = new ObjectOutputStream(os);
            ObjectInputStream ois = new ObjectInputStream(is);

            System.out.println("Before fetching person!1");
            Person tekst = (Person) ois.readObject();
            
            personList.add(tekst);
                    
            //oos.flush();
            socket.close();
            /*
            if (operation == 1) {
            System.out.println("Adding a Person to PersonServer");
            Person person = (Person) ois.readObject();
            personList.add(person);
            
            }
            if (operation == 2) { System.out.println("Read an int..!"); }
            /*int index = (Integer) ois.readObject();
            System.out.println("Fetching person at index " + index + "from PersonServer");
            Person person = personList.get(index);
            oos.writeObject(person);
            oos.flush();
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}
